package netty.http;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import netty.handler.NettyServerHandler;

/**
 * @author ：朱博
 * @description：Http协议的服务程序
 * @date ：2021/4/17 15:26
 */
public class TestServer {

    public static void main(String[] args) throws InterruptedException {

        /**
         * 创建EventLoopGroup[只是处理连接请求]
         */
        EventLoopGroup bossGroup = new NioEventLoopGroup(1);

        /*
         * 创建EventWorkGroup [只是处理业务]
         */
        EventLoopGroup workGroup = new NioEventLoopGroup();


        //创建服务器端启动的对象
        ServerBootstrap bootstrap = new ServerBootstrap();
        //绑定两个线程组
        bootstrap.group(bossGroup,workGroup)
                .channel(NioServerSocketChannel.class)//使用NioServerSocketChannel实现通道类型
                .option(ChannelOption.SO_BACKLOG,128)//设置线程队列连接等待的个数
                .childOption(ChannelOption.SO_KEEPALIVE,true)
                .childHandler(new TestServerInitializer());


        System.err.println("服务器已经开启......Loading====>>>>>>>");

        ChannelFuture bind = bootstrap.bind(9090).sync();//绑定端口 并且启动服务器

        //对关闭通道进行监听
        bind.channel().closeFuture().sync();


    }

}
